package 优先级队列比较方法;

/**
 * 比较器
 * 接口
 * 匿名内部类
 * 重写equals
 */

import java.util.Comparator;
import java.util.Objects;
import java.util.PriorityQueue;

class Card {
    public int num;
    public String suit;

    public Card(int num,String suit) {
        this.num =num;
        this.suit = suit;
    }

    @Override
    public String toString() {
        return "Card{" +
                "num=" + num +
                ", suit='" + suit + '\'' +
                '}';
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Card card = (Card) o;
        return num == card.num && Objects.equals(suit, card.suit);
    }

//    @Override
//    public int hashCode() {
//        return Objects.hash(num, suit);
//    }
}

/**
 * 比较器
 */
class NunComparator implements Comparator<Card>{
    @Override
    public int compare(Card o1, Card o2) {
        return o1.num-o2.num;
    }
}

/**
 * 匿名内部类
 *  PriorityQueue<Card> priorityQueue=new PriorityQueue<Card>(new Comparator<Card>() {
 *             @Override
 *             public int compare(Card o1, Card o2) {
 *                 return o1.num-o2.num;
 *             }
 *         });
 */

///**
// *抽象类解决offer报错
// * 实现接口
// * implements Comparable<Card>
// */
//class Card implements Comparable<Card>{
//    public int num;
//    public String suit;
//
//    public Card(int num,String suit) {
//        this.num =num;
//        this.suit = suit;
//    }
//
//    @Override
//    public int compareTo(Card o) {
//        return this.num-o.num;
//    }
//
//    @Override
//    public String toString() {
//        return "Card{" +
//                "num=" + num +
//                ", suit='" + suit + '\'' +
//                '}';
//    }
//}
public class test {

    public static void main(String[] args) {
        PriorityQueue<Card> priorityQueue=new PriorityQueue<Card>(new Comparator<Card>() {
            @Override
            public int compare(Card o1, Card o2) {
                return o1.num-o2.num;
            }
        });
        priorityQueue.offer(new Card(1,"黄"));
        priorityQueue.offer(new Card(2,"黑"));
        priorityQueue.offer(new Card(3,"绿"));
        priorityQueue.offer(new Card(3,"绿"));

        Card card1=new Card(3,"绿");
        Card card2=new Card(3,"绿");
        Card card3=card1;


        System.out.println(card1.equals(card2));


        //System.out.println(new Card(3,"绿").compareTo(new Card(3,"dsffaf")));


       // System.out.println(1);

    }
}
